package mystruts;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.person;

import com.opensymphony.xwork2.ActionSupport;

import java.util.ArrayList;
public class personAction extends ActionSupport{
	
	public String addform() {
		this.LOG.info("我是addform");
		return "addform";
	}
	
	public String add() {
		this.LOG.info("我是add");
		this.LOG.info("vo.getUser:"+vo.getUser());
		dao.persondao dao=new dao.persondao();
		dao.insert(vo);
		ArrayList<person> list=this.shopcar();
		list.add(vo);
		return "add";
	}	
	
	person vo=new vo.person();
	
	public String list(){
		//this.setRslist(this.shopcar());
		return "list";
	}
	
	public String updateform(){
		this.setVo(this.shopcar().get(index));
		return "updateform";
	}

	public String update(){
		ArrayList<person> list=this.shopcar();
		list.set(index,vo);
		return "update";
	}
	
	public String delete(){
		ArrayList<person> list=this.shopcar();
		list.remove(index);
		return list();
	}
	
	public vo.person getVo() {
		return vo;
	}

	public void setVo(vo.person vo) {
		this.vo = vo;
	}
	
	ArrayList<person> shopcar(){
		HttpSession session=ServletActionContext.getRequest().getSession();
		ArrayList<person> list=(ArrayList<person>)session.getAttribute("list");
		if(list==null){
			list=new ArrayList<person>();
			session.setAttribute("list", list);
		}
		return list;
	}
	
	//ArrayList<person> rslist;

	public ArrayList<person> getRslist() {
		return shopcar();
	}

	
	  public void setRslist(ArrayList<person> rslist) {
		//this.rslist = rslist;
	}
	
	
	int index;

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
}
